<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <link rel="stylesheet" href="./lib/layui/css/layui.css" />
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>
    <script th:inline="none">
        layui.use(["table","layer"],function(){
            var table=layui.table;
            var layer=layui.layer;
            table.render({
                elem:"#qustiontable",
                url:"getqusbypage",
                page:true,
                toolbar:"#toolbardemo",
                cols:[[
                    {field: 'id', title: '编号', width:80, sort: true, fixed: 'left'}
                    ,{field: 'teachername', title: '出题人', width:80}
                    ,{field: 'content', title: '题目', width:80}
                    ,{field: 'con1', title: '选项1', width:80}
                    ,{field: 'con2', title: '选项2', width:80}
                    ,{field: 'con2', title: '选项3', width:80}
                    ,{field: 'con4', title: '选项4', width:80}
                    ,{field: 'answer', title: '答案', width:80,sort: true, templet: '#getans'}
                    ,{fixed: 'right', width:260, align:'center', toolbar: '#barDemo'}
                ]]
            })
            table.on("toolbar(qustiontable)",function(obj){
                if(obj.event=="add"){
                   layer.open({
                       type:2,
                       title:"添加题目",
                       area:["500px","550px"],
                       content:"toaddqus"
                   })
                }
            });
            table.on("tool(qustiontable)",function(obj){
                if(obj.event=="edit"){
                   layer.open({
                       type:2,
                       title:"编辑题目",
                       area:["500px","550px"],
                       content:"toupdatequs?id="+obj.data.id
                   })
                }else if(obj.event=="del"){
                    layer.confirm('您确定要删除该数据吗？', {
                        btn: ['确定', '取消'] //可以无限个按钮
                    }, function(index, layero){
                        $.ajax({
                            url:"delqus",
                            data:{"id":obj.data.id},
                            type:"post",
                            dataType:"json",
                            success:function(dataJson){
                                if(dataJson.code==200){
                                    location.reload();
                                }else{
                                    layer.msg(dataJson.msg);
                                }
                            }
                        })
                    }, function(index){

                    })
                }
            })
        })
    </script>
    <script type="text/javascript" id="toolbardemo" th:inline="none">
        <a class="layui-btn" lay-event="add">添加题目</a>
    </script>
    <script type="text/javascript" id="barDemo" th:inline="none">
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑题目</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除题目</a>
    </script>
</head>
<body>
<table id="qustiontable" lay-filter="qustiontable"></table>
</body>
</html>